﻿using Autofac;
using AutoMapper;
using Public_Class_Library;
using System.Net.Http;
using System.Reflection;

namespace O.M.Helper
{
    /// <summary>
    /// 批量注入类
    /// </summary>
    public class Production_Module : Autofac.Module
    {
        /// <summary>
        /// 重写load方法
        /// </summary>
        /// <param name="builder"></param>
        protected override void Load(ContainerBuilder builder)
        {
            //通过Assembly这个类来动态加载程序集,然后AutoFac会扫描加载的程序集中的类型寻找可以注册为服务的类型
            var Repository = Assembly.Load("O.M.Production.Infrastuecure");//类库名
            var Service = Assembly.Load("O.M.Production.Application");

            //将程序集注入到AutoFac当中
            //AsImplementedInterfaces()比如你现在是一个实现类，他会自动找到它的接口来实现
            builder.RegisterAssemblyTypes(Repository).Where(x => x.Name.EndsWith("Repository")).AsImplementedInterfaces();
            //EndsWith()他会找到尾部这个字符串的类
            builder.RegisterAssemblyTypes(Service).Where(x => x.Name.EndsWith("Service")).AsImplementedInterfaces();
            //注入单个文件
            builder.RegisterType(typeof(Cross_service_Helper));
 
            base.Load(builder);
        }
    }
}
